#pragma once

#include <cstdint>
#include <unordered_map>
#include <vector>
#include "DbDataManager.h"
#include "User.h"

using namespace xncc::types;
class UserManager
{
  public:
    UserManager()  = default;
    ~UserManager() = default;

    void loadUsers();

    UserLoginRes handleUserLoginReq(const char* buf, uint32_t len, thread_id_t tid, connection_id_t connId);

    UserListRes handleUserListReq(const char* buf, uint32_t len, thread_id_t tid, connection_id_t connId);

    user_id_t handleDisconnected(connection_id_t id, thread_id_t tid);

    UserChatRes
    handleUserChatMsg(const char* buf, uint32_t len, thread_id_t tid, connection_id_t connId, UserChatMsg& msg);

    UserRegisterRes handleUserRegisterReq(const char* buf, uint32_t len, thread_id_t tid, connection_id_t connId);

    AddDelFriendRes handleAddDelFriendReq(const char* buf, uint32_t len, thread_id_t tid, connection_id_t connId);

    const User* getUser(user_id_t id) const;

    User* getUser(user_id_t id);

  private:
    std::unordered_map<user_id_t, User>        users_;
    std::unordered_map<connection_id_t, User*> conn2User_;
    DbDataManager                              db_manager_;
    std::set<std::string>                      user_names_;
};